# 作者: 肖老师
# 2024年12月19日03时29分00秒
# xxxrlmk@163.com

# 字典套列表
mydict = {'Li': ['M', 7],
          'Zhang': ['E', 2],
          'Wang': ['P', 3],
          'Du': ['C', 2],
          'Ma': ['C', 9],
          'Zhe': ['H', 7]}


# 字典的items方法：把键和值拼为元组，返回一个可迭代对象
# for i in mydict.items():
#     print(i)
print(sorted(mydict.items(), key=lambda v: v[1][1]))

gameresult = [
    {"name": "Bob", "wins": 10, "losses": 3, "rating": 75.00},
    {"name": "David", "wins": 3, "losses": 5, "rating": 57.00},
    {"name": "Carol", "wins": 4, "losses": 5, "rating": 57.00},
    {"name": "Patty", "wins": 9, "losses": 3, "rating": 71.48}]

from operator import itemgetter

print(sorted(gameresult, key=itemgetter('rating', 'name')))

# 第一个升序，第二个降序怎么搞
tuples = [(3, 5), (1, 2), (2, 4), (3, 1), (1, 3)]
print(sorted(tuples, key=lambda x: (x[0], -x[1])))
